package com.binest.keyEvent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.binest.common.annotation.Log;
import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.enums.BusinessType;
import com.binest.keyEvent.domain.KeyEvent;
import com.binest.keyEvent.service.IKeyEventService;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.common.core.page.TableDataInfo;

/**
 * 关键事件Controller
 * 
 * @author wwd
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/keyEvent")
public class KeyEventController extends BaseController
{
    @Autowired
    private IKeyEventService keyEventService;

    /**
     * 查询关键事件列表
     */
    @PreAuthorize("@ss.hasPermi('keyEvent:keyEvent:list')")
    @GetMapping("/list")
    public TableDataInfo list(KeyEvent keyEvent)
    {
        startPage();
        List<KeyEvent> list = keyEventService.selectKeyEventList(keyEvent);
        return getDataTable(list);
    }

    /**
     * 导出关键事件列表
     */
    @PreAuthorize("@ss.hasPermi('keyEvent:keyEvent:export')")
    @Log(title = "关键事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KeyEvent keyEvent)
    {
        List<KeyEvent> list = keyEventService.selectKeyEventList(keyEvent);
        ExcelUtil<KeyEvent> util = new ExcelUtil<KeyEvent>(KeyEvent.class);
        util.exportExcel(response, list, "关键事件数据");
    }

    /**
     * 获取关键事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('keyEvent:keyEvent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(keyEventService.selectKeyEventById(id));
    }

    /**
     * 新增关键事件
     */
    @PreAuthorize("@ss.hasPermi('keyEvent:keyEvent:add')")
    @Log(title = "关键事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KeyEvent keyEvent)
    {
        return toAjax(keyEventService.insertKeyEvent(keyEvent));
    }

    /**
     * 修改关键事件
     */
    @PreAuthorize("@ss.hasPermi('keyEvent:keyEvent:edit')")
    @Log(title = "关键事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KeyEvent keyEvent)
    {
        return toAjax(keyEventService.updateKeyEvent(keyEvent));
    }

    /**
     * 删除关键事件
     */
    @PreAuthorize("@ss.hasPermi('keyEvent:keyEvent:remove')")
    @Log(title = "关键事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(keyEventService.deleteKeyEventByIds(ids));
    }
}
